<template>
	<view :class="current==1||current==3?'container-b':'container'">
		<view class="title_box">
			<view @click="clickItem(item)" v-for="(item, i) in list" :key="i" style="margin-left: 0rpx;">
				<view style="position: relative;display: flex;">
					<view class="dian" v-if="current==item.value"></view>
					<view :class="item.value==current?'yname':'noname'">{{item.name}}</view>
				</view>
			</view>
		</view>
		<view v-if="current == 1">
			<view style="background-color: #f4f4f4;padding:0 20rpx;border-radius: 20px;line-height: 40px;">
				<u-input placeholder="咨询问题" v-model="form.title" placeholderStyle="color: #A5A4A4"></u-input>
			</view>
			<view style="margin-top: 20rpx;">
				<textarea placeholder-style="color: #A5A4A4" v-model="form.info" placeholder="问题描述"
					style="background-color: #f4f4f4;padding:0 20rpx;border-radius: 40rpx;padding: 20rpx;width: auto;"></textarea>
			</view>
			<view style="margin-top: 20rpx;">
				<view style="margin-left: 20rpx;">选择图片</view>
				<u-upload :fileList="fileList" :action="uploadurl" @on-uploaded="afterRead" @on-remove="deletePic"
					uploadIcon="photo-fill" multiple :maxCount="10" :header='header'></u-upload>
			</view>
			<view style="font-size: 25rpx;color: #A5A4A4;margin-top: 20rpx;">支持jpg、jpeg、gif、png、bmp格式,大小不能大于5M</view>
			<view style="margin-top: 150rpx;">
				<view v-if="reward_money==''"
					style="margin-top: 150rpx;line-height: 50px;text-align: center;margin: auto;color: #FFFFFF;background-color: #FFB400; border-radius: 50%;font-size: 50rpx;width: 50px;height: 50px"
					@click="open()">
					赏
				</view>
				<view v-else style="display: flex;align-items: center;justify-content: center;">
					<view style="color: #de2415;font-size: 30rpx;font-weight: bold;">
						打赏金额: {{reward_money}}元
					</view>
					<view
						style="margin-left: 10rpx;font-size: 20rpx;background-color: #f5f5f5;color: #999999;padding: 0 5px;"
						@click="open()">修改</view>
				</view>
			</view>
			<view @click="submit" style="background-color: #de2415;
						margin-top: 100rpx;
						color: white;
						text-align: center;
						line-height: 80rpx;
						border-radius: 40rpx;
						font-size: 30rpx;">
				咨询问题
			</view>

			<u-popup :mask="true" v-model="show" mode="center" @close="close" @open="open">
				<view style="background-color: #FFFFFF;border-radius: 20px;width: 50vw;padding-bottom: 40rpx;">
					<view style="line-height: 40px;background-color: #eeeeee;text-align: center;
					    border-top-left-radius: 20px;
						border-top-right-radius: 20px;">打赏金额</view>
					<view style="margin: 20px;display: flex; align-items: center;justify-content: center;">
						<u-input placeholder="输入金额" border="surround" type="decimal" clearable v-model="reward_money"
							style="width: 100px;margin: auto;text-align: center;">
						</u-input>
						<view style="margin-left: 20rpx;">元</view>
					</view>
					<view @click="reward()"
						style="margin: 20px;;line-height: 30px;color: #FFFFFF;margin: auto;text-align: center;width: 100px;border-radius: 20px;background-color: #ff0000;">
						确认</view>
				</view>
			</u-popup>
		</view>

		<view class="" v-if="current == 2" style="">
			<view v-if="item.re_info" v-for="(item, index) in dataList" :key="index"
				style="background: #FFFFFF;border-radius: 20rpx;padding: 20rpx;">
				<view style="display: flex;">
					<!-- <view style="width: 68rpx;height: 68rpx;">
						<image style="width: 68rpx;height: 68rpx;" src="/static/image/fenxiao5.png"></image>
					</view> -->
					<view>
						<u-parse :html="item.re_info" :tag-style="vuex_parse_style"
							:domain="vuex_config.config ? vuex_config.config.upload.cdnurl : ''"
							@linkpress="diylinkpress"></u-parse>
					</view>
					<!-- <view style="display: flex;margin-left: 20rpx;width: 100%;">
						<view style="display: flex;flex-direction: column;flex: 1;">
							<view style="color: #333333;font-size: 28rpx;font-weight: 400;display: flex;">
								蔷薇
								<view style="color: #CCCCCC;font-size: 20rpx;line-height: 40rpx;margin-left: 10rpx;">
									12:00 </view>
							</view>
							<view style="font-size: 24rpx;font-weight: 400;color: #999999;line-height: 20px;">
								{{item.re_info}}
							</view>
						</view>
						<view style="display: flex; align-items: flex-end;color: #999999;line-height: 35rpx;">
							<u-icon
								name="https://huboshizb.bigchun.com/uploads/20221008/d0a949b2f3a301f88d63398948f7eb3f.png"
								size="30" style="margin-right: 10rpx;"></u-icon>
							回复
						</view>
					</view> -->
				</view>
				<view style="background: #F5F5F5;border-radius: 20rpx;margin-top: 20rpx;padding: 20rpx;">
					<view style="color: #333333;font-size: 28rpx;line-height: 50rpx;font-weight: 500;">
						{{item.title}}
					</view>
					<view style="color: #999999;font-size: 24rpx;line-height: 40rpx; overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;">
						{{item.info}}
					</view>
				</view>
			</view>
		</view>

		<view class="" v-if="current == 3">
			<view class="">
				<view style="display: flex;
							align-items: center;
							justify-content: center;
							margin: 50rpx;">
					<image src="/static/image/fenxiao5.png" mode="" style="width: 92rpx;height: 92rpx;"></image>
				</view>
				<view style="color: #333333;background-color: #F5F5F5;border-radius: 50rpx;height: 80rpx;padding: 0 40rpx;display: flex;
					align-items: center;
				    font-weight: 500;
				    font-family: Source Han Sans CN;">
					<u-icon name="rmb" color="#DE2415" size="40" style="margin-right: 20rpx;"></u-icon>
					18.88
				</view>
				<view style="color: #FFFFFF;background-color: #DE2415;border-radius: 50rpx;height: 80rpx;padding: 0 40rpx;display: flex;
					align-items: center;
				    font-weight: 500;
				    font-family: Source Han Sans CN;
					display: flex;
					justify-content: center;
					margin-top: 100rpx;">
					支付
				</view>
			</view>
		</view>

		<view class="" v-if="current == 4">
			<view @click="toZxxq(item.id)" v-for="(item, index) in dataList" :key="index"
				style="background: #FFFFFF;border-radius: 20rpx;padding: 20rpx;margin-bottom: 30rpx;">
				<view style="background: #F5F5F5;border-radius: 20rpx;padding: 20rpx;">
					<view style="color: #333333;font-size: 28rpx;line-height: 50rpx;font-weight: 500;">
						{{item.title}}
					</view>
					<view style="color: #999999;font-size: 24rpx;line-height: 40rpx; overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;">
						{{item.info}}
					</view>
				</view>
				<view style="display: flex;height:60rpx;align-items: center;padding: 0 20rpx;">
					<view
						style="flex: 1;color: #DE2415;font-size: 36rpx;font-weight: bold;font-family: Source Han Sans CN;line-height: 36rpx;">
						￥{{item.money}}
					</view>
					<view style="color: #23AAFF;font-size: 28rpx; font-weight: 400;">
						立即查看
					</view>
				</view>
			</view>
			<!-- <view style="background: #FFFFFF;border-radius: 20rpx;padding: 20rpx;">
				<view style="background: #F5F5F5;border-radius: 20rpx;padding: 20rpx; ">
					<view style="color: #333333;font-size: 28rpx;line-height: 50rpx;font-weight: 500;">
						欧泊品种怎么分析与鉴定
					</view>
					<view style="color: #999999;font-size: 24rpx;line-height: 40rpx; overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;">
						欧泊作为继“五皇一后”崛起的另外一种宝贵宝石，以其美 丽的外表...
					</view>
				</view>
				<view style="display: flex;height:60rpx;align-items: center;padding: 0 20rpx;">
					<view
						style="flex: 1;color: #DE2415;font-size: 36rpx;font-weight: bold;font-family: Source Han Sans CN;line-height: 36rpx;">
						￥18.88
					</view>
					<view style="color: #DE2415;font-size: 28rpx;    font-weight: 400;">
						点击继续查看
					</view>
				</view>
			</view> -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: 1,
				list: [{
						name: '我要咨询',
						value: 1
					},
					{
						name: '咨询答复',
						value: 2
					},
					// {
					//   name: '咨询打赏',
					//   value: 3
					// },
					{
						name: '我的咨询',
						value: 4
					}
				],
				show: false,
				fileList: [],
				reward_money: '',
				form: {
					title: "",
					info: "",
					imgs: "",
					reward_money: ""
				},
				dataList: []
			}
		},
		computed: {
			header() {
				return {
					token: this.vuex_token || '',
					uid: this.vuex_user.id || 0
				};
			},
			formdata() {
				let multipart = (this.vuex_config.config && this.vuex_config.config.upload.multipart) || '';
				let isObj = this.$u.test.object(multipart);
				if (isObj) {
					return this.vuex_config.config.upload.multipart;
				}
				return {};
			},
			uploadurl() {
				if (!this.vuex_config.upload) {
					return '';
				}
				return this.vuex_config.upload.uploadurl;
			}
		},
		onLoad(options) {
			if (options.current != null) {
				this.current = options.current
			}
		},
		onShow() {
			if (this.current != 1) {
				this.getList();
			}
		},
		methods: {

			toZxxq(id) {
				this.goPage('/pages/jewel/consultdetail?id=' + id)
			},

			clickItem(val) {
				console.log("clickItem", val)
				this.current = val.value;
				this.is_update = true;
				console.log(val.value);
				if (val.value != 1) {
					this.getList();
				}
				this.getMsg(this.current)
			},
			getList() {
				this.$api.myinquiry().then(res => {
					if (res.code) {
						this.dataList = res.data;
						// this.dataList.forEach((item, index) => {
						// 	if (item.createtime != null) {
						// 		item.createtime = this.$util.tsFormatTime(item.createtime * 1000, "Y年M月D日")
						// 	}
						// })
					}
				});
			},
			getMsg(current) {
				if (current === 4) {

				}
			},
			submit() {
				console.log('this.fileList', this.fileList)
				this.$api.inquiryAdd({
					title: this.form.title,
					info: this.form.info,
					imgs: this.fileList.toString(),
					reward_money: this.reward_money,
					method: 'miniapp'
				}).then(res => {

					if (res.code == 1) {

						if (this.reward_money) {
							// #ifdef MP-WEIXIN
							// await this.subscribe();
							uni.requestPayment({
								provider: 'wxpay',
								timeStamp: res.data.timeStamp,
								nonceStr: res.data.nonceStr,
								package: res.data.package,
								signType: res.data.signType,
								paySign: res.data.paySign,
								success: async rest => {
									// this.$u.toast('支付成功！');
									// await this.subscribe();
									// this.reward_money = ""
									// this.getData()
									// url='https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx101715513646580c6435af10838dfd0000&amp;package=2408443049&amp;redirect_url=https%3A%2F%2Fhuboshizb.bigchun.com%2Faddons%2Fepay%2Findex%2Freturnx%2Fpaytype%2Fwechat%2Fout_trade_no%2F20230410171551939021'
									this.$u.toast('提交成功');
									setTimeout(() => {
										uni.$u.route({
											type: 'back'
										})
									}, 1000);
								},
								fail: err => {
									console.log(err);
									if (err.errMsg = "requestPayment:fail cancel") {
										this.$u.toast('取消支付');
									} else {
										this.$u.toast('支付失败');
									}

								}
							});
							// #endif
						} else {
							this.$u.toast('提交成功');
							setTimeout(() => {
								uni.$u.route({
									type: 'back'
								})
							}, 1000);
						}

					} else {
						this.$u.toast('上传失败');
					}
				})
			},
			onUploaded(e, name) {
				console.log(e, name);
				this.form['images__' + name] = e
					.map(item => {
						return item.response.data.url;
					})
					.join(',');
			},
			onRemove(index, lists, name) {
				this.form['images__' + name] = lists
					.map(item => {
						return item.response.data.url;
					})
					.join(',');
			},
			reward() {


				// return

				this.form.reward_money = this.reward_money;
				this.show = false
			},


			// subscribe() {
			// 	return new Promise((resolve, reject) => {
			// 		wx.requestSubscribeMessage({
			// 			tmplIds: this.vuex_config.tpl_ids,
			// 			complete: res => {
			// 				console.log(res);
			// 				if (res.errMsg == 'requestSubscribeMessage:ok') {
			// 					this.$api.subscribe({ tpl_ids: res, order_sn: this.order.order_sn }).then(res => {
			// 						console.log(res);
			// 					});
			// 				}
			// 				resolve();
			// 			}
			// 		});
			// 	});
			// },
			//打赏
			// async reward() {

			// 	this.$api.reward({
			// 		article_id: this.article_id,
			// 		reward_money: this.reward_money,
			// 		method: "miniapp"
			// 	}).then(async res => {

			// 		if (res.code == 1) {
			// 			// #ifdef MP-WEIXIN
			// 			await this.subscribe();
			// 			uni.requestPayment({
			// 				provider: 'wxpay',
			// 				timeStamp: res.data.timeStamp,
			// 				nonceStr: res.data.nonceStr,
			// 				package: res.data.package,
			// 				signType: res.data.signType,
			// 				paySign: res.data.paySign,
			// 				success: async rest => {
			// 					this.$u.toast('支付成功！');
			// 					await this.subscribe();
			// 					this.reward_money = ""
			// 					this.getData()
			// 				},
			// 				fail: err => {
			// 					console.log(err);
			// 					if (err.errMsg = "requestPayment:fail cancel") {
			// 						this.$u.toast('取消支付');
			// 					} else {
			// 						this.$u.toast('支付失败');
			// 					}

			// 				}
			// 			});
			// 			// #endif
			// 		}

			// 		// this.$u.toast('打赏成功');
			// 		// this.reward_money = ""
			// 		// this.getData()
			// 	})
			// 	this.show = false
			// 	return

			// 	let that = this
			// 	uni.request({
			// 		url: 'https://huboshizb.bigchun.com/api/info/reward', //仅为示例，并非真实接口地址。
			// 		method: 'POST',
			// 		data: {
			// 			article_id: this.article_id,
			// 			reward_money: this.reward_money,
			// 			method: "wap"
			// 		},
			// 		success: (res) => {
			// 			console.log('打赏res', res)
			// 			uni.showToast({
			// 				title: '打赏成功'
			// 			})
			// 			that.reward_money = ""
			// 			that.dataList = []
			// 			that.getData()

			// 		}
			// 	});
			// 	this.show = false
			// },

			open() {
				console.log(this.show);
				this.show = true
			},
			close() {
				this.show = false
				// 
			},
			// 删除图片
			deletePic(index) {
				this.fileList.splice(index - 1, 1);
				console.log('this.fileList', this.fileList)
			},
			// 新增图片
			async afterRead(event) {
				const newArr = JSON.parse(JSON.stringify(event))
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				this.fileList = [];
				newArr.forEach(item => {
					if (item && item.response) {
						this.fileList.push(item.response.data.fullurl);
					}
				});
				this.fileList = this.fileList.map(item => {
					const idx = item.indexOf('.com')
					return item.slice(idx + 4)
				})
				console.log('this.fileList', this.fileList)
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>
<style>
	.container {
		padding: 22px 11px;
		height: 100vh;
		background-color: #f5f5f5;
	}

	.container-b {
		padding: 22px 11px;
		height: 100vh;
		background-color: #ffffff;
	}

	.title_box {
		display: flex;
		justify-content: space-between;
		padding: 10px;
	}

	.dian {
		background-size: 100% 100%;
		width: 35rpx;
		height: 35rpx;
		background-image: url("/static/image/fenxiao26.png");
		position: absolute;
		top: -5px;
		left: -7px;
	}

	.noname {
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #333333;
		z-index: 9;
		/* width: 100rpx; */
	}

	.yname {
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: bold;
		color: #333333;
		line-height: 30rpx;
		z-index: 9;
	}
</style>
<style>
</style>
